#ifndef _WMI_CONNECTIONMANAGER_H
#define _WMI_CONNECTIONMANAGER_H

/***********************************************************************************
** @file	wmi_connectionmanager.h
** @author	Carlos Armando Orellana Pacolla
** @author  Nestor Felipe
** @date	Jul 28, 2010
**
** @desc	This class is a implementation of the WMI_IConnectionManager class. Manage
**			the creation of connections for WMI (Windows Management Instrumentation)
************************************************************************************/

// WMI includes
#include <Wbemidl.h>
#include <comdef.h>
# pragma comment(lib, "wbemuuid.lib")
# pragma comment(lib, "credui.lib")
# pragma comment(lib, "comsuppw.lib")
#include <wincred.h>
#include <strsafe.h>
#include <iostream>
#include "wmi_iconnectionmanager.h"
#include "wmi_connectionmanager.h"
#include "wmi_connection.h"
#include "wmi_constants.h"
#include "wmi_common.h"

class SOEXPORT WMI_ConnectionManager : public WMI_IConnectionManager 
{
public:
	/**
	* Create a new Instance of WMI_ConnectionManager
	*/
	WMI_ConnectionManager()
		: _pSvcMng(NULL), _userAcctMng(NULL), _pLocMng(NULL)
	{		
	}

	/**
	* This method create a new wmi connection to local machine
	*
	* @param user is the user name for authentication process
	* @param password is the user password for authentication process
	* @param conNameSpace is the wmi name space for wmi connection. Sample //root/default
	* @param conRes is the WMI_IConnection class. The result of this method is stored in this reference
	* @return a integer thats represent the state of operation. 0 if the createConnection is correct, 1 if
	* the createConnection method is not correct.
	*/	
	virtual WMI_HResult 
	createConnection(const std::wstring user,const std::wstring password, const std::wstring  conNameSpace, WMI_Connection& conRes);

	/**
	* This method create a new wmi connection to remote machine
	*
	* @param user is the user name for authentication process
	* @param password is the user password for authentication process
	* @param pc_name is the remote IP or host name
	* @param conNameSpace is the wmi name space for wmi connection. Sample //root/default
	* @param conRes is the WMI_IConnection class. The result of this method is stored in this reference
	*/	
	virtual WMI_HResult 
	createConnection(const std::wstring user, const std::wstring  password, const std::wstring  pc_name, const std::wstring  conNameSpace, WMI_Connection& conRes);


	/**
	* Set the default COM security configuration
	*/
	static WMI_HResult
	initCOMSecurityConfiguration();

	/**
	* Close the default COM security configuration
	*/
	static void 
	closeCOMSecurityConfiguration();

	
private:
	/**
	* Use the IWbemLocator interface to obtain the initial namespace pointer to the IWbemServices interface for 
	* WMI on a specific host computer. You can access Windows Management itself using the IWbemServices pointer, 
	* which is returned by the IWbemLocator::ConnectServer method.
	*/
	IWbemLocator* _pLocMng;

	/**
	* Is used by clients and providers to access WMI services
	*/
	IWbemServices* _pSvcMng;

	/**
	* This structure represents a user name and password.
	* A pointer to a COAUTHIDENTITY structure is a member 
	* of the COAUTHINFO structure, which specifies authentication settings for remote activation requests
	*/
	COAUTHIDENTITY* _userAcctMng;
};

#endif 